package com.ruoyi.web.controller.construction.supertube;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.construction.Team;
import com.ruoyi.system.mapper.construction.TeamMapper;
import com.ruoyi.system.service.construction.TeamService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Random;
@Api(value = "超管施工队类别和租赁服务类别接口", tags = {"超管施工队类别和租赁服务类别接口"})
@RestController
@RequestMapping("/super/team")
public class ConstructionTeamController extends BaseController {

    @Autowired(required = false)
    private TeamService teamMapper;

    @PreAuthorize("@ss.hasPermi('super:team:list')")
    @GetMapping("/list")
    public TableDataInfo list(Team team)
    {
        startPage();
        List<Team> list = teamMapper.apifindAllListTeamOne(team);
        return getDataTable(list);
    }



    /**
     * 导出供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('super:team:export')")
    @Log(title = "供应商分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Team team)
    {
        List<Team> list = teamMapper.apifindAllListTeamOne(team);
        ExcelUtil<Team> util = new ExcelUtil<Team>(Team.class);
        return util.exportExcel(list, "team");
    }

    /**
     * 获取供应商分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('super:team:query')")
    @GetMapping(value = "/{teamId}")
    public AjaxResult getInfo(@PathVariable("teamId") Long teamId)
    {
        return AjaxResult.success(teamMapper.apifindAllListTeamById(teamId));
    }

    /**
     * 新增供应商分类
     */
    @PreAuthorize("@ss.hasPermi('super:team:add')")
    @Log(title = "供应商分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Team team)
    {
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String num =stringBuilder.toString();
        team.setTeamCode(num);
        team.setTeamStatus("1");
//        team.setTeamType("0");
        team.setModifiedTime(new Date());
        team.setDelFlag("0");
        team.setStatusType("1");
        team.setSupplierId(0);
        return toAjax(teamMapper.apiInsertTeam(team));
    }

    /**
     * 修改供应商分类
     */
    @PreAuthorize("@ss.hasPermi('super:team:edit')")
    @Log(title = "供应商分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Team team)
    {
        return toAjax(teamMapper.apiUpdateTeam(team));
    }

    /**
     * 删除供应商分类
     */
    @PreAuthorize("@ss.hasPermi('super:team:remove')")
    @Log(title = "供应商分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{teamId}")
    public AjaxResult remove(@PathVariable Long[] teamId)
    {
        return toAjax(teamMapper.apiDeleteTeamByIds(teamId));
    }

// TODO: 以上是施工队分类接口***********************************

//  TODO: 以下是租赁服务接口************************************

    @PreAuthorize("@ss.hasPermi('super:team:listTwo')")
    @GetMapping("/listTwo")
    public TableDataInfo listTwo(Team team)
    {
        startPage();
        List<Team> list = teamMapper.apifindAllListTeamTwo(team);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('super:team:addTwo')")
    @Log(title = "供应商分类", businessType = BusinessType.INSERT)
    @PostMapping("/two/addTwo")
    public AjaxResult addTwo(@RequestBody Team team)
    {
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String num =stringBuilder.toString();
        team.setTeamCode(num);
        team.setTeamStatus("1");
        team.setTeamType("1");
        team.setModifiedTime(new Date());
        team.setDelFlag("0");
        team.setStatusType("1");
        team.setSupplierId(0);
        return toAjax(teamMapper.apiInsertTeamTwo(team));
    }

    /**
     * 修改供应商分类
     */
    @PreAuthorize("@ss.hasPermi('super:team:editTwo')")
    @Log(title = "供应商分类", businessType = BusinessType.UPDATE)
    @PutMapping("/two/updateTeamTwo")
    public AjaxResult editTwo(@RequestBody Team team)
    {
        return toAjax(teamMapper.apiUpdateTeamTwo(team));
    }

    /**
     * 删除供应商分类
     */
    @PreAuthorize("@ss.hasPermi('super:team:removeTwo')")
    @Log(title = "供应商分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/two/{teamId}")
    public AjaxResult removeTwo(@PathVariable Long[] teamId)
    {
        return toAjax(teamMapper.apiDeleteTeamByIdsTwo(teamId));
    }

    /**
     * 导出供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('super:team:exportTwo')")
    @Log(title = "供应商分类", businessType = BusinessType.EXPORT)
    @GetMapping("/two/export")
    public AjaxResult exportTwo(Team team)
    {
        List<Team> list = teamMapper.apifindAllListTeamTwo(team);
        ExcelUtil<Team> util = new ExcelUtil<Team>(Team.class);
        return util.exportExcel(list, "team");
    }

}
